function shadowboxAddNewick() {

    Shadowbox.open( { content: "",
                      player: "html",
                      title: "Add tree in Newick format",
                      height: $(window).height() * .75,
                      width: $(window).width() * .75,
                      options: { onFinish: shadowboxCreateAddNewickDialog } } );
}

function shadowboxCreateAddNewickDialog() {

    $('#sb-player').append(
        makeEl('div').attr( { 'class': 'topMargin1 fullWidth' } ).append(
            makeEl('div').attr( { 'class': 'right fLeft width15' } ).text('Name : '),
            makeEl('div').attr( { 'class': 'fLeft width80 center' } ).append(
                makeEl('input').attr( { 'class': 'width80', 'id': 'newickName', 'type': 'text' } ) ),
            makeEl('div').attr( { 'class': 'clear' } ) ),
        makeEl('div').attr( { 'class': 'topMargin1 fullWidth height50' } ).append(
            makeEl('div').attr( { 'class': 'right fLeft width15 fullHeight' } ).text('Newick : ').append(
                makeEl('div').attr( { id: 'fileUploader', 'class': 'blue smallText' } ).text('Upload Newick File') ),
            makeEl('div').attr( { 'id': 'newickContainer', 'class': 'fLeft width80 center fullHeight' } ).append(
                makeEl('textarea').attr( { 'class': 'width80 fullHeight', 'id': 'newickString' } ),
                makeEl('span').attr( { 'id': 'newickFileSelectedNotice', 'class': 'rightMargin1 hide' } ).text('File selected for upload'),
                makeEl('a').attr( { 'id': 'cancelNewickFileUploadLink', 'href': 'javascript:void(0);', 'class': 'hide' } ).text('Cancel').click( showNewickStringUploadDialogue ) ),
            makeEl('div').attr( { 'class': 'clear' } ) ),
        makeEl('div').attr( { 'class': 'topMargin1 fullWidth' } ).append(
            makeEl('div').attr( { 'class': 'right fLeft width15' } ).text('Comments : '),
            makeEl('div').attr( { 'class': 'fLeft width80 center' } ).append(
                makeEl('textarea').attr( { 'class': 'width80', 'id': 'newickComment' } ) ),
            makeEl('div').attr( { 'class': 'clear' } ) ),
        makeEl('div').attr( { 'class': 'topMargin1 width85 right' } ).append(
            makeEl('a').attr( { 'class': 'rightMargin1', 'href': 'javascript:void(0);', id: 'shadowboxSubmitButton' } ).click( ajaxAddNewick ).text('Add'),
            makeEl('a').attr( { 'href': 'javascript:void(0);' } ).click( closeShadowbox ).text('Close') ) );

    $('#newickName').focus();

    
    globals.uploader = new AjaxUpload( 'fileUploader', { action: '/' + globals.applicationName + '/default/newickUpload',
                                                         name: 'newickFile',
                                                         autoSubmit: false,
                                                         onChange: newickFileSelected,
                                                         onComplete: fileUploaderOnComplete,
                                                         onSubmit: fileUploaderOnSubmit } );
}

function fileUploaderOnComplete( file, response ) {

    handleAddNewickResponse( { response: response, name: $('#newickName').val(), comment: $('#newickComment').val() } );
    closeShadowbox();
}


function fileUploaderOnSubmit( file, extension ) {
    
    var nameField = $('#newickName');
    var commentField = $('#newickComment');

    if( nameField.val().trim() == '' ) { nameField.val( file ); }

    if( commentField.val().trim() == '' ) { commentField.val( getCurrentDateTime() ); }

    globals.uploader.setData( { newickName: nameField.val(), newickComment: commentField.val() } );
}

